CC=gcc
CXX=g++
CFLAGS=-Wall $(DEBUG) $(DEFINITIONS) $(CINCLUDES) $(CMISCFLAGS) $(CE) -fPIC
CPPFLAGS=-Wall $(DEBUG) $(CPPINCLUDES) $(DEFINITIONS) $(CPPMISCFLAGS) $(CE) -fPIC
DEBUG=-O0 -g3
CMISCFLAGS=
CPPMISCFLAGS=
DEFINITIONS=-DLINUX_OS
CINCLUDES=-I. -I$(GDIR)/include/GIMnetAP -I$(GDIR)/utils -I$(GDIR)/bitestream
CPPINCLUDES=-I. -I$(GDIR)/include/GIMnetAP -I$(GDIR)/utils \
-I$(GDIR)/bitestream \
`xml2-config --cflags` -I$(GDIR)/GIMI -I$(GDIR)/GIMI/datatypes \
`wx-config --cflags --unicode=no` \
-I$(MACIPATH) -I$(MACI_INTERFACE_PATH) -I$(MACI_DRIVER_PATH) -I$(MACI_BUS_PATH) \
-I$(MACI_INTERFACE_PATH)/MaCICtrl -I$(MACI_INTERFACE_PATH)/Alarm \
-I$(MACI_INTERFACE_PATH)/Gimbo \
$(INCGIMI)

LD=g++
LDFLAGS=
LIBS=-lrt -lpthread `xml2-config --libs` `wx-config --libs std,gl --unicode=no` $(LIBSGIMI)
GDIR=..
SRCSC=
SRCSCPP=main.cpp \
Browser.cpp \
Loader.cpp \
GimboSettings.cpp \
Gimbo_forms.cpp \
GimboLoaderFrame.cpp \
GimboConnectDialog.cpp \
GimboSettingsFrame.cpp \
$(MACIPATH)/launcher/executor.cpp \
$(MACIPATH)/launcher/directory.cpp

MACIPATH=$(GDIR)/MaCI

VPATH=
#CPPGIMI=
#CGIMI=
PYLIB=`python-config --includes`

## Build GIMI and it's dependencies.
## Files are set to CGIMI and CPPGIMI variables
include $(GDIR)/GIMI/Makefile.gimi

## Include MaCI-stuff
include $(MACIPATH)/interfaces/MaCI-interfaces.Makefile

## Construct final lists of CPP and C objects
OBJS_GIMUI_C=$(SRCSC:.c=.o)
OBJS_GIMUI_CPP=$(SRCSCPP:.cpp=.opp)
OBJSC=$(CGIMI:.c=.o)
OBJSCPP=$(CPPGIMI:.cpp=.opp) $(MACI_BASE_SRC_CPP:.cpp=.opp) $(MACI_EXT_SRC_CPP:.cpp=.opp) \
$(MACI_INTERFACE_GIMBO_COMMON_CPP:.cpp=.opp) $(MACI_INTERFACE_GIMBOCLIENT_CPP:.cpp=.opp)

## Define compiles and links
COMPILEC=$(CC) $(CFLAGS) $(CINCLUDES) -c
COMPILECPP=$(CXX) $(CPPFLAGS) $(CPPINCLUDES) -c
LINK=$(LD) $(LDFLAGS) $(LIBS)

.PHONY: all clean

Gimbo: $(OBJSC) $(OBJSCPP) $(OBJS_GIMUI_C) $(OBJS_GIMUI_CPP)
	@$(LINK) -o $@ $(OBJSC) $(OBJSCPP) $(OBJS_GIMUI_C) $(OBJS_GIMUI_CPP)
	@echo "      [LD] $@"

dist:	Gimbo components
	rm -rf ./dist
	mkdir -p ./dist
	cp -v Gimbo ./dist
	cp -rv ./components ./dist
	find ./dist -iname "*.opp" -o -iname "*.o" -o -iname "*.dopp" -o -iname "*.do" | xargs rm -v
	find ./dist -iname "*.cpp" -o -iname "*.hpp" -o -iname "*.c" -o -iname "*.h" \
	-o -iname "*.log" -o -name "CVS" -o -name "Makefile" | xargs rm -vr
	find ./dist -type f | xargs strip &>/dev/null

all: Gimbo components

.PHONY: components
components:
	cd components; ./make_in_all

clean:
	rm -f $(OBJS_GIMUI_C) $(OBJS_GIMUI_CPP) Gimbo *.out *~ *.d *.dpp

sumversion:
	$(GDIR)/utils/sum_versions Gimbo

realclean: clean
	rm -f $(OBJSC) $(OBJSCPP) *.out *~ *.d *.dpp

####### Component Class Python Wrap ##############
ComponentWrap:
	swig $(INCLUDES) -c++ -python -o Component_Python.cpp Component.i
		$(COMPILECPP) $(PYLIB) \
		Component_Python.cpp -o Component_Python.opp
	$(LINK) -shared -fPIC -o _GimboComponent.so \
		Component_Python.opp $(OBJSC) $(OBJSCPP) \
		$(OBJS_GIMUI_C) $(OBJS_GIMUI_CPP) \
		-lrt -lpthread `xml2-config --libs`
GimboWrap: $(OBJSC) $(OBJSCPP) $(OBJS_GIMUI_C) $(OBJS_GIMUI_CPP)
	swig $(INCLUDES) -c++ -python -o Types_Python.cpp Types.i
		$(COMPILECPP) $(PYLIB) \
		Types_Python.cpp -o Types_Python.opp
	$(LINK) -shared -fPIC -o _GimboTypes.so \
		Types_Python.opp $(OBJSC) $(OBJSCPP) \
		$(OBJS_GIMUI_C) $(OBJS_GIMUI_CPP) \
		-lrt -lpthread `xml2-config --libs`


###################################################

## Below this is dependency generation stuff, no need to change.
## Compile rule for all .o (.c) file
%.o:    %.c
	@$(COMPILEC) -o $@ $<
	@echo "      [CC] $<"

## Compile rule for all .opp (.cpp) files
%.opp:  %.cpp
	@$(COMPILECPP) -o $@ $<
	@echo "      [CXX] $<"
